package com.xms.sdk.core.query;

import java.util.LinkedList;
import java.util.List;

/**
 * <p>
 * QueryExpression
 * </p>
 *
 * @author migo
 * @since 2021/9/1
 */
public class QueryExpression extends QueryBase{
    
    public boolean Distinct = false;

    public int Top;

    public PagingInfo PageInfo;

    public List<LinkEntity> LinkEntities = new LinkedList<>();

    public FilterExpression Criteria = new FilterExpression();

    public List<OrderExpression> Orders = new LinkedList<>();

    public ColumnSet ColumnSet = new ColumnSet();

    public QueryExpression()
    {
    }

    public QueryExpression(String entityName)
    {
        super.EntityName = entityName;
    }

    public void AddColumns(String... columns)
    {
        this.ColumnSet.addColumns(columns);
    }

    public void AddColumns(List<String> columns)
    {
        this.ColumnSet.addColumns(columns);
    }

    public void AddOrder(String attributeName, OrderType orderType)
    {
        this.Orders.add(new OrderExpression(attributeName, orderType));
    }

    public LinkEntity AddLink(String linkToEntityName, String linkFromAttributeName, String linkToAttributeName)
    {
        return this.AddLink(linkToEntityName, linkFromAttributeName, linkToAttributeName, JoinOperator.Inner);
    }

    public LinkEntity AddLink(String linkToEntityName, String linkFromAttributeName, String linkToAttributeName, JoinOperator joinOperator)
    {
        LinkEntity linkEntity = new LinkEntity(this.EntityName, linkToEntityName, linkFromAttributeName, linkToAttributeName, joinOperator);
        this.LinkEntities.add(linkEntity);
        return linkEntity;
    }
}
